package com.cxm.qyyz.utils;

import android.os.Environment;
import android.text.TextUtils;

import com.cxm.qyyz.app.App;

/**
 * @author baiyinhu
 */
public class FileConfig {

    private FileConfig() {
    }

    private static class Inner {
        static final FileConfig mInstance = new FileConfig();
    }

    public static FileConfig getInstance() {
        return FileConfig.Inner.mInstance;
    }


    //storage/emulated/0/Android/data/app_package_name/cache
    public String getCacheDirPath() {
        if ( Environment.getExternalStorageState() .equals(Environment.MEDIA_MOUNTED) ){
            if (isSdCardExist()) {
                if (null == App.getInstance().getExternalCacheDir())return "";
                return App.getInstance().getExternalCacheDir().getAbsolutePath();
            } else {
                if (null == App.getInstance().getCacheDir())return "";
                return App.getInstance().getCacheDir().getAbsolutePath();
            }
        }
        return App.getInstance().getCacheDir().getPath();
    }

    public String getSDCardPath() {
        return Environment.getExternalStorageDirectory().getAbsolutePath();
    }

    public String getHomeMusicPath(String name) {
        if (TextUtils.isEmpty(getCacheDirPath()))return "";
        return getCacheDirPath() + name;
    }

    //判断sd卡是否存在
    public boolean isSdCardExist() {
        return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    }
}